#!/usr/bin/env bash
# vim:  fdm=marker fmr=[[[,]]] cms=\ #%s

bin_path=$(dirname $0)
if [ ${bin_path:0:1} != '/' ]
then
    bin_path=$(pwd)/$bin_path
fi
CLIENT=$bin_path/../../tool/snclient
ADDR=localhost:10010

GETDBPASSWD()
{ #[[[
    local dbname
    read -p "dbname[DB1]: " dbname
    local dbuser
    read -p "dbuser[dbuser]: " dbuser
    $CLIENT $ADDR GETDBPASSWD "${dbname:-DB1}" "${dbuser:-dbuser}"
} #]]]

GETPRIKEYPASSWD()
{ #[[[
    $CLIENT $ADDR GETPRIKEYPASSWD
} #]]]

GETUSERPASSWDKEY()
{ #[[[
    $CLIENT $ADDR GETUSERPASSWDKEY
} #]]]

main()
{ #[[[
    if [[ ! -x $CLIENT ]]
    then
        echo "snclient not found"
        return 1
    fi

    local option
    echo -n "\
Services:
    1) GETDBPASSWD db user
    2) GETPRIKEYPASSWD
    3) GETUSERPASSWDKEY
Input: "
    read option
    if [ -z "$option" ]
    then
        echo  "Error: input null"
        return 1
    fi
    case $option in
        1) GETDBPASSWD ;;
        2) GETPRIKEYPASSWD ;;
        3) GETUSERPASSWDKEY ;;
        *)
            echo "Error: option($option) not supported"
            return 1
            ;;
    esac
} #]]]

main
exit $?
